#include<bits/stdc++.h>
using namespace std;

struct car{
    int d;
    int v;
    int a;
};
struct rangee{
    bool exclude=true;
    int ll,rr;
};
int t;
int n,m,L,V;
int ans1,ans2;
car c[100005];
int p[100005];  //the place of the detectors
int pn[100005]; //pn[i]:the num of cars that can be detected by detector i
rangee ra[100005];
int main(){
    freopen("detect.in","r",stdin);
    freopen("detect.out","w",stdout);
    cin>>t;
    while(t--){
        cin>>n>>m>>L>>V;
        ans1=0;ans2=m;
        for(int i=1;i<=n;i++){
            cin>>c[i].d>>c[i].v>>c[i].a;
            ra[i].exclude=true;
        }
        for(int i=1;i<=m;i++){
            cin>>p[i];
            pn[i]=0;
        }
        for(int i=1;i<=n;i++){  //exceeded speed?
            if(c[i].a==0){
                if(c[i].d<=p[m]&&c[i].v>V){
                    ans1++;
                    int j;
                    for(j=m;p[j]>=c[i].d;j--)
                        pn[j]++;
                    j++;
                    ra[i].exclude=false;
                    ra[i].ll=j;ra[i].rr=m;
                }
            }
            else if(c[i].a<0){
                if(c[i].v<=V)continue;  //sure not to exceed the V
                int lf=1,re=m;
                while(lf!=re){
                    int mm=lf+(re-lf)/2;
                    if(p[mm]>c[i].d)re=mm;
                    else lf=mm;
                    if((lf+(re-lf)/2)==mm)break;
                }
                int pos1=re;  //the first detector that can detect the car(perhaps)
                long long mid=V*V-c[i].v*c[i].v;
                int pl=mid/(2*c[i].a)+c[i].d;  //the last integer address that the car exceed V
                if(p[pos1]<=pl){
                    ans1++;
                    int lf=1,re=m;
                    while(lf!=re){
                        int mm=lf+(re-lf)/2;
                        if(p[mm]>pl)re=mm;
                        else lf=mm;
                        if((lf+(re-lf)/2)==mm)break;
                    }
                    int pos2=re-1;  //the last detector that can detect the car with its exceeded speed
                    for(int j=pos1;j<=pos2;j++)
                        pn[j]++;
                    ra[i].exclude=false;
                    ra[i].ll=pos1;ra[i].rr=pos2;
                }
            }
            else{   //c[i].v>0;
                int pl;
                long long mid=V*V-c[i].v*c[i].v;
                pl=floor(mid/(2*c[i].a)*1.000000+c[i].d);  //the first integer address that the car exceed V
                if(pl<=p[m]){
                    ans1++;
                    int lf=1,re=m;
                    while(lf!=re){
                        int mm=lf+(re-lf)/2;
                        if(p[mm]>pl)re=mm;
                        else lf=mm;
                        if((lf+(re-lf)/2)==mm)break;
                    }
                    int pos=re;
                    ra[i].exclude=false;
                    ra[i].ll=pos;ra[i].rr=m;
                }
            }
        }

        //solve ans2;

        int maxx;
        do{
            maxx=0;int pos; //pos:the can't-delete detector
            for(int i=1;i<=m;i++){
                if(pn[i]>maxx){
                    maxx=pn[i];
                    pos=i;
                }
            }

            if(maxx){
                ans2--;
                for(int i=1;i<=n;i++){
                    if(ra[i].exclude)continue;
                    if(ra[i].ll<=pos&&ra[i].rr>=pos){
                        ra[i].exclude=true;
                        for(int j=ra[i].ll;j<=ra[i].rr;j++)
                            pn[j]--;
                    }
                }
            }
        }while(maxx);
        cout<<ans1<<" "<<ans2<<endl;
    }
    return 0;
}
